package test

import org.scalatest.FunSuite
import agent.ccs.Act
import agent.ccs.Prefix
import agent.ccs.PPrefix
import agent.ccs.PPrefix
import agent.ccs.PNil
import agent.ccs.CCSAgent
import agent.ccs.PParallel

class HashCodeChecker extends FunSuite {
  

  test("Act hashcode abd equivalence") {
    val names = List("a", "bbb", "cc", "Iamact!")
        var first: List[Act] = List[Act]()
        var second: List[Act] = List[Act]()


        names foreach {
          name => {
            first = first ++ List(new Act(Symbol(name), false, None))
                second = second ++ List(new Act(Symbol(name), false, None))
          }
        }
        // Hashcode
        for (i <- 0 until first.length) {
          assert(first(i).hashCode() === second(i).hashCode)
        }

        // Value
        for (i <- 0 until first.length) {
          assert(first(i) === second(i))
        }

  }

  test("Prefix hashcode and equivalence") {
    val names = List("a", "bbb", "cc", "Iamact!")
        var first: List[Prefix] = List()
        var second: List[Prefix] = List()


        names foreach {
          name => {
            first = first ++ List(new Prefix(new Act(Symbol(name), false, None), None))
                second = second ++ List(new Prefix(new Act(Symbol(name), false, None), None))
          }
        }
        // Hashcode
        for (i <- 0 until first.length) {
          assert(first(i).hashCode() === second(i).hashCode)
        }

        // Value
        for (i <- 0 until first.length) {
          assert(first(i) === second(i))
        }

  }



  test("Prefix agent and equivalence") {
    val names = List("a", "bbb", "cc", "Iamact!")
        var prefixes: List[Prefix] = List()

        var pprefixes1: List[PPrefix] = List()
        var pprefixes2: List[PPrefix] = List()



        names foreach {
          name => {
            prefixes = prefixes ++ List(new Prefix(new Act(Symbol(name), false, None), None))
          }
        }

        for (i <- 0 until prefixes.length) {
          pprefixes1 = pprefixes1 ++ List(new PPrefix(List(prefixes(i)), CCSAgent.makeAgent(new PNil)))
              pprefixes2 = pprefixes2 ++ List(new PPrefix(List(prefixes(i)), CCSAgent.makeAgent(new PNil)))
        }


        // Hashcode
        for (i <- 0 until pprefixes1.length) {
          assert(pprefixes1(i).hashCode() === pprefixes2(i).hashCode)
        }

        // Value
        // Hashcode
        for (i <- 0 until pprefixes1.length) {
          assert(pprefixes1(i) === pprefixes2(i))
        }
  }  

  test("Parallel agents hash codes and equivalences") {
    val names = List("a", "bbb", "cc", "Iamact!")
        var prefixes: List[Prefix] = List()

        var pprefixes1: List[PPrefix] = List()
        var pprefixes2: List[PPrefix] = List()
        var paragents1: List[PParallel] = List()
        var paragents2: List[PParallel] = List()


        names foreach {
          name => {
            prefixes = prefixes ++ List(new Prefix(new Act(Symbol(name), false, None), None))
          }
        }

        for (i <- 0 until prefixes.length) {
          pprefixes1 = pprefixes1 ++ List(new PPrefix(List(prefixes(i)), CCSAgent.makeAgent(new PNil)))
          pprefixes2 = pprefixes2 ++ List(new PPrefix(List(prefixes(i)), CCSAgent.makeAgent(new PNil)))
        }

        for (i <- 0 until pprefixes1.length) {
          paragents1 = paragents1 ++ List(new PParallel(List(CCSAgent.makeAgent(pprefixes2(i)), CCSAgent.makeAgent(pprefixes1(i)))))
          paragents2 = paragents2 ++ List(new PParallel(List(CCSAgent.makeAgent(pprefixes1(i)), CCSAgent.makeAgent(pprefixes2(i)))))
        }

        // Hashcode
        for (i <- 0 until paragents1.length) {
          assert(paragents1(i).hashCode() === paragents2(i).hashCode)
        }

        // Value
        // Hashcode
        for (i <- 0 until paragents1.length) {
          assert(paragents1(i) === paragents2(i))
        }
  }
  
  
  
  


}